package com.ctg.payroll2.dao.workflow.imp;

import java.sql.SQLException;
import java.util.Map;

import com.ctg.payroll2.bean.filter.workflow.FlowRoleFilter;
import com.ctg.payroll2.bean.po.workflow.FlowRole;
import com.ctg.payroll2.dao.workflow.WorkflowRoleDao;
import com.ctg.platform.orm.ibatis.IbatisEntityDao;
import com.ctg.platform.util.Page;

@SuppressWarnings("unchecked")
public class WorkflowRoleDaoImp extends IbatisEntityDao implements
		WorkflowRoleDao {
	private String getNameSpace() {
		return this.getClass().getSimpleName();
	}

	public Page queryFlowRoleByFilter(FlowRoleFilter filter) {
		return pagedQueryByFilter(this.getClass(), filter,
				".queryFlowRoleByFilter_count", ".queryFlowRoleByFilter_query");
	}

	public Long insertFlowRole(FlowRole role) throws SQLException {
		if (role == null) {
			return null;
		}
		return (Long) getSqlMapClient().insert(
				getNameSpace() + ".insertFlowRole", role);
	}

	public int deleteFlowRoleByIds(String ids) throws SQLException {
		return getSqlMapClient().delete(
				getNameSpace() + ".deleteFlowRoleByIds", ids);
	}

	public int updateFlowRole(FlowRole role) throws SQLException {
		return getSqlMapClient().update(getNameSpace() + ".updateFlowRole",
				role);
	}

	public Page queryFlowUserByRole(Object paraMap, Integer start, Integer limit) {
		return this.pagedQuery(this.getClass(), (Map<String, Object>) paraMap,
				start, limit, ".selectFlowUserByRoleCount",
				".selectFlowUserByRole");
	}

	public Page queryRoleUserNotInRoleUser(Object paraMap, Integer start,
			Integer limit) {
		return this.pagedQuery(this.getClass(), (Map<String, Object>) paraMap,
				start, limit, ".selectRoleUserNotInRoleUserCount",
				".selectRoleUserNotInRoleUser");
	}

	public Integer deleteRoleUser(Object paraMap) {
		return (Integer) getSqlMapClientTemplate().delete(
				"WorkflowRoleDaoImp.deleteRoleUser", paraMap);
	}

	public void insertUserByRole(Object paraMap) {
		getSqlMapClientTemplate().insert("WorkflowRoleDaoImp.insertUserByRole",
				paraMap);
	}
}
